package com.cjr.mq.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;



@Configuration
public class QueueConfig {
    // 队列名称
    public final static String QUEUE = "queue-1";
    public final static String QUEUE_2 = "queue-2";
    // 交换机名称
    public final static String FANOUT_EXCHANGE = "fanoutExchange-1";
    public final static String DIRECT_EXCHANGE = "directExchange-1";
    public final static String TOPIC_EXCHANGE = "topicExchange-1";
    //定义topic的key
    public final static String TOPIC_KEY_ONE = "topic.*";
    public final static String TOPIC_KEY_MANY = "topic.#";
    public final static String TOPIC_KEY_ONLY = "topic.msg.a";



    //定义队列1
    @Bean
    Queue queue1() {
        return new Queue(QUEUE);
    }

    //定义队列2
    @Bean
    Queue queue2() {
        return new Queue(QUEUE_2);
    }

    //定义fanoutExchange交换机
    @Bean
    FanoutExchange fanoutExchange(){
        return new FanoutExchange(FANOUT_EXCHANGE);
    }

    //定义directExchange交换机
    @Bean
    DirectExchange directExchange(){
        return new DirectExchange(DIRECT_EXCHANGE);
    }

    //定义topicExchange交换机
    @Bean
    TopicExchange topicExchange(){
        return new TopicExchange(TOPIC_EXCHANGE);
    }

    @Bean
    Binding bindingQueue1(){
        return BindingBuilder.bind(queue1()).to(topicExchange()).with(TOPIC_KEY_ONLY);
    }
    @Bean
    Binding bindingQueue2(){
        return BindingBuilder.bind(queue2()).to(topicExchange()).with(TOPIC_KEY_ONE);
    }

    /*//将队列1绑定到交换机
    @Bean
    Binding bindingQueue1(){
        return BindingBuilder.bind(queue1()).to(fanoutExchange());
    }

    //将队列2绑定到交换机
    @Bean
    Binding bindingQueue2(){
        return BindingBuilder.bind(queue2()).to(fanoutExchange());
    }*/

}
